

*Assign the directory for the table + figure output
global tnf .\TablesAndFigures\


********************************************************************************
* Table 10 - The 2013 CFPB intervention and racial disparities in auto lending
********************************************************************************

********************
* Table 10 Cols 1-3:  DiD / Triple-Diff tests for auto loan interest rates
********************
use Data_AutoLoans, clear // synthetic data created in _0_GenerateSyntheticData.do

* Same controls as in prior interest rate tests
global y apr
global democontrols sex_female age ln_hmda_app_income
global autocontrols ln_aua_credit_open lti_aua
global creditscore l1_vantage_v3_score
global creditcontrols ln_l1_all_balance_open new_dti ln_l1_all_pastdue2 aua_debtshare_all    	   
global zipcontrols ln_acs_pipc ln_popdensity acs_edu_bagrad acs_commute_usecar
global FE aua_termofrecenttrade timetomort statefips#year origmonth 

estimates clear
local ifcond
*note: interaction terms that would be subsumed by FEs are commented out
*Diff in Diff around 2013 CFPB Intervention
eststo c1: reghdfe ${y} minXpost race_minority /*post*/  ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

*Triple Diff split on non-bank financing share
eststo c2: reghdfe ${y} minXhighXpost minXpost minXhigh highXpost race_minority /*post*/ nonbank_hi   ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	
			
*Triple Diff split on racial bias
eststo c3: reghdfe ${y} minXpostXbias minXpost minXbias /*postXbias*/ race_minority /*post*/ /*racialbias_hi*/   ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	


********************
* Table 10 Cols 4-6:  DiD / Triple-Diff tests for auto credit approval
********************
use Data_MainMatchedPanel, clear // synthetic data created in _0_GenerateSyntheticData.do
keep if year >=2011

* Same controls as in prior credit access tests
global y  aua_accessratio_annual_w0
global democontrols sex_female age ln_hmda_app_income
global creditscore l1_vantage_v3_score 
global creditcontrols ln_l1_all_balance_open new_dti ln_l1_all_pastdue2   	   
global zipcontrols ln_acs_pipc ln_popdensity acs_edu_bagrad acs_commute_usecar
global FE timetomort statefips#year

local ifcond
*note: interaction terms that would be subsumed by FEs are commented out
*Diff in Diff around 2013 CFPB Intervention
eststo c4: reghdfe ${y} minXpost race_minority /*post*/  ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

*Triple Diff split on non-bank financing share
eststo c5: reghdfe ${y} minXhighXpost minXpost minXhigh highXpost race_minority /*post*/ nonbank_hi   ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

*Triple Diff split on racial bias
eststo c6: reghdfe ${y} minXpostXbias minXpost minXbias /*postXbias*/ race_minority /*post*/ /*racialbias_hi*/   ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	


********************
* Table 10 Cols 7-9: DiD / Triple-Diff falsification tests for credit cards
********************
*note: continue using the same data and globals defined for Table 10 Cols 4-6. 

*now set the y as the credit card limit increase:
	global y bcc_credit_inc  
*restrict sample to those who search for both auto credit and CC credit during the year:	
	local ifcond if aua_accessratio_annual_w0!=. & bcc_accessratio_annual_w0!=. 
*rescale bcc_credit_inc, because in esttab we are going to multiply the coeffs by 100 
*   (to make cols 1-6 in percentage points) and we don't want it to apply to columns 7-9
	replace bcc_credit_inc = bcc_credit_inc / 100 
 
*note: interaction terms that would be subsumed by FEs are commented out
*Diff in Diff around 2013 CFPB Intervention
eststo c7: reghdfe ${y} minXpost race_minority /*post*/  ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

*Triple Diff split on non-bank financing share
eststo c8: reghdfe ${y} minXhighXpost minXpost minXhigh highXpost race_minority /*post*/ nonbank_hi   ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

*Triple Diff split on racial bias
eststo c9: reghdfe ${y} minXpostXbias minXpost minXbias /*postXbias*/ race_minority /*post*/ /*racialbias_hi*/   ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        `ifcond', absorb(${FE}) cluster(statefips#year)   	

				
********************
* Build Table 10 ... 9 columns: APR, Approval (Auto), and CC Limit Inc.
********************
esttab c1 c2 c3 c4 c5 c6 c7 c8 c9 using ${tnf}T_CFPBDiffs_9Cols ,title("") ///
	replace tex frag ///
	drop(${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} aua_debtshare_all ${zipcontrols}) order(race_minority minXpost minXhighXpost) noomitted b(%12.3f) se(%12.3f) transform(100*@ 100)   ///
	stats(r2 N, fmt(%12.3f %12.0gc) labels("R-Squared" "Observations")) se star(* .10 ** .05 *** .01) ///
	label nogaps nonumbers



		
	
********************************************************************************
* Produce Figure 3
********************************************************************************

********************
*Step 1: Using the actual credit bureau/HMDA auto loans dataset, we ran the following
*        code to estimate minorities' additional interest rate each year 
********************        
/*
* Same controls as in prior interest rate tests
global y apr
global democontrols sex_female age ln_hmda_app_income
global autocontrols ln_aua_credit_open lti_aua
global creditscore l1_vantage_v3_score
global creditcontrols ln_l1_all_balance_open new_dti ln_l1_all_pastdue2 aua_debtshare_all    	   
global zipcontrols ln_acs_pipc ln_popdensity acs_edu_bagrad acs_commute_usecar
global FE aua_termofrecenttrade timetomort statefips#year origmonth 

***** Look at racial difference each year	
forvalues y=2011/2017 {
	gen d_`y' = 0
	replace d_`y' = 1 if year == `y'
	}
forvalues y=2011/2017 {	
	gen minorityX`y'= race_minority * d_`y'
	}
	
global minorityXyearvars minorityX2011 minorityX2012 minorityX2013 minorityX2014 minorityX2015 minorityX2016 minorityX2017 

local moreif
*full country
reghdfe ${y} ${minorityXyearvars} ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        if ${y}!=. `moreif', absorb(${FE}) cluster(statefips#year) 			
regsave using YearEstimates_apr_all, replace ci level(90)

*high nonbank-financing areas
reghdfe ${y} ${minorityXyearvars} ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        if nonbank_hi==1 `moreif' , absorb(${FE}) cluster(statefips#year) 			
regsave using YearEstimates_apr_high, replace ci level(90)

*low nonbank-financing areas
reghdfe ${y} ${minorityXyearvars} ${democontrols} ${autocontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        if nonbank_hi==0 `moreif' , absorb(${FE}) cluster(statefips#year) 			
regsave using YearEstimates_apr_low, replace ci level(90)

*put all 3 sets of yearly estimates into one data set
foreach v in all high low {
	use YearEstimates_apr_`v', clear
	keep if regexm(var, "minorityX")
	gen year = regexs(1) if regexm(var, "minorityX(.*)")
	destring year, replace
	keep year coef ci_lower ci_upper stderr
	order year coef ci_lower ci_upper stderr
	ren coef `v'_coef 
	ren ci_lower `v'_ci_lower
	ren ci_upper `v'_ci_upper
	ren stderr `v'_se
	save, replace
	}
use YearEstimates_apr_all, clear 
merge 1:1 year using YearEstimates_apr_high, update
drop _merge
merge 1:1 year using YearEstimates_apr_low, update
drop _merge
save YearEstimates_apr, replace
erase YearEstimates_apr_all.dta 
erase YearEstimates_apr_high.dta 
erase YearEstimates_apr_low.dta 
*/

********************
*Step 2: Use the actual resultant data set (included here as Data_YearEstimates_apr.dta)
*        to produce Figures 3A, 3C, and 3D
********************  
use Data_YearEstimates_apr, clear
replace year = 2012.95 if year == 2013

*full country (3A)
serrbar all_coef all_se year, ///
	scale (1.645) ylabel(-.005(.005).02, grid gmax gmin) ytitle("Additional APR Paid by Minorities") xlabel(2011(2)2017) xtitle("") ///
	xline(2013) ///
	title("Rates -- Full Sample" " ") name(all, replace)

*high nonbank-financing areas (3C)
serrbar high_coef high_se year, ///
	scale (1.645) ylabel(-.005(.005).02, grid gmax gmin) ytitle("Additional APR Paid by Minorities") xlabel(2011(2)2017) xtitle("") ///
	xline(2013) ///
	title("Rates -- High Non-Bank Financing Areas" " ") name(high, replace)

*low nonbank-financing areas (3D)
serrbar low_coef low_se year, ///
	scale (1.645) ylabel(-.005(.005).02, grid gmax gmin) ytitle("Additional APR Paid by Minorities") xlabel(2011(2)2017) xtitle("") ///
	xline(2013) ///
	title("Rates -- Low Non-Bank Financing Areas" " ") name(low, replace)

	
	
********************
*Step 3: Using the actual credit bureau/HMDA matched panel, we ran the following
*        code to estimate minorities' reduction in loan approval each year 
********************   	
/*
* Same controls as in prior credit access tests
global y  aua_accessratio_annual_w0
global democontrols sex_female age ln_hmda_app_income
global creditscore l1_vantage_v3_score 
global creditcontrols ln_l1_all_balance_open new_dti ln_l1_all_pastdue2   	   
global zipcontrols ln_acs_pipc ln_popdensity acs_edu_bagrad acs_commute_usecar
global FE timetomort statefips#year

***** Look at racial difference each year
keep if year >=2011

forvalues y=2011/2017 {
	gen d_`y' = 0
	replace d_`y' = 1 if year == `y'
	}
forvalues y=2011/2017 {	
	gen minorityX`y'= race_minority * d_`y'
	}
	
global minorityXyearvars minorityX2011 minorityX2012 minorityX2013 minorityX2014 minorityX2015 minorityX2016 minorityX2017 

*full country
reghdfe ${y} ${minorityXyearvars} ${democontrols} ${creditscore} ${creditcontrols} ${zipcontrols} ///
        , absorb(${FE}) cluster(statefips#year)   	
regsave using YearEstimates_credit_all, replace ci level(90)

*clean data set
local v all
use YearEstimates_credit_`v', clear
keep if regexm(var, "minorityX")
gen year = regexs(1) if regexm(var, "minorityX(.*)")
destring year, replace
keep year coef ci_lower ci_upper stderr
order year coef ci_lower ci_upper stderr
ren coef `v'_coef 
ren ci_lower `v'_ci_lower
ren ci_upper `v'_ci_upper
ren stderr `v'_se
save YearEstimates_credit, replace
erase YearEstimates_credit_all.dta 
*/

********************
*Step 4: Use the actual resultant data set (included here as Data_YearEstimates_credit.dta)
*        to produce Figure 3B
******************** 
use Data_YearEstimates_credit, clear
replace year = 2012.95 if year == 2013
serrbar all_coef all_se year, ///
	scale (1.645) ylabel(-.03(.01).02, grid gmax gmin) ytitle("Minorities' Estimated Reduction" "in Auto Loan Approval") xlabel(2011(2)2017) xtitle("") ///
	xline(2013) ///
	title("Approvals -- Full Sample" " ") name(all_approvals, replace)


	
********************
* Step 5: Combine the graphs to build Figure 3 
********************
graph combine all all_approvals high low, xsize(5) altshrink rows(2) name(combined, replace)	  
*manually add the "CFPB Intervention" text and A,B,C,D labels

graph export ${tnf}F_YearEstimates.pdf , replace name(combined)	
	
	




